package com.dragon.cotroller;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.entity.User;
import com.dragon.service.UserService;
import org.aopalliance.intercept.Interceptor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("user")
public class UserAction {
    @Autowired
    UserService userService;

    @PostMapping ("m1")
    public boolean m1(@Param("name") String a, int b, String c){

        User k =new User();
        k.setName(a);
        k.setAge(b);
        k.setEmail(c);

        boolean w = userService.save(k);
        return w;
    }

    @PutMapping("m2")
    public int m2 (@Param("User") User user){


        return  userService.getBaseMapper().updateById(user);
    }
    @DeleteMapping("m3")
    public int m3( int id){

        return userService.getBaseMapper().deleteById(id);
    }
    @GetMapping("m4")
    public User m5( int id){

        return userService.getBaseMapper().selectById(id);
    }
    @GetMapping("m5")
    public Page<User> m6(@Param("name") String name,  int PageNum,  int PageSize){


        QueryWrapper<User> s=new QueryWrapper<>();
        User u=new User();
        u.setName(name);
        s.setEntity(u);
        Page<User> objectPage = new Page<>(PageNum, PageSize);//第1页，5行数据
        userService.getBaseMapper().selectPage(objectPage, s);//分页查询 条件为null
        objectPage.getTotal();//获取总记录数
        objectPage.getRecords();//获取数据
        objectPage.getRecords().forEach(System.out::println);//打印输出

        return objectPage ;
    }




}